<template>
	<view class="page">
		<view class="bar_info" :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class="title_bar">
				<view class="title_bar_left" @tap.stop="isBack">
					<u-icon size="38" name="arrow-left"></u-icon>
				</view>
				<view class="title_bar_center">
					<text v-if="is_pay == 0">设置提现密码</text>
					<text v-else>修改提现密码</text>
				</view>
				<view class="title_bar_right"></view>
			</view>
		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		<view class="set_content">
			<view class="set_list">
				<view class="list_item" v-if="is_pay == 1">
					<view class="list_item_left">原密码</view>
					<view class="list_item_right">
						<u-input v-model="security_code" :clearable="false" placeholder="请输入原密码(6位数字)" placeholder-style="color:#999;font-size: 30rpx;" type="number" maxlength="6" input-align="right" height="42" />
					</view>
				</view>
				<view class="list_item">
					<view class="list_item_left">新密码</view>
					<view class="list_item_right">
						<u-input v-model="pay_password" :clearable="false" placeholder="请输入新密码(6位数字)" placeholder-style="color:#999;font-size: 30rpx;" type="number" maxlength="6" input-align="right" height="42" />
					</view>
				</view>
				<view class="list_item no_border">
					<view class="list_item_left">确认密码</view>
					<view class="list_item_right">
						<u-input v-model="pay_password_code" :clearable="false" placeholder="请输入确认密码(6位数字)" placeholder-style="color:#999;font-size: 30rpx;" type="number" maxlength="6" input-align="right" height="42" />
					</view>
				</view>
			</view>
		</view>
		
		<view class="save_btn" @tap.stop="submit">保存</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				is_pay: 0,  // 0未设置  1已设置
				security_code: "",
				pay_password: "",
				pay_password_code: "",
			}
		},
		onLoad(option) {
			let {is_pay} = option;
			if (is_pay !== undefined) this.is_pay = is_pay;
		},
		methods: {
			submit() {
				// 设置支付密码
				if (this.is_pay == 0) {
					if (!this.pay_password) {
						this.$message.info('请输入新密码');
						return;
					}
					if (this.pay_password.length < 6) {
						this.$message.info('请输入6位数字新密码');
						return;
					}
					if (!this.pay_password_code) {
						this.$message.info('请输入确认密码');
						return;
					}
					if (this.pay_password !== this.pay_password_code) {
						this.$message.info('两次输入密码不一致');
						return;
					}
					this.$api.post(global.apiUrls.postSetPayPsd, {
						pay_password: this.pay_password,
						pay_password_code: this.pay_password_code
					}).then(res => {
						this.$message.info(res.data.msg);
						if (res.data.code == 1) {
							setTimeout(() => {
								uni.navigateBack();
							}, 800)
						}
					})
				} else {
					// 修改支付密码  postEditPayPsd
					if (!this.security_code) {
						this.$message.info('请输入原密码');
						return;
					}
					if (this.security_code.length < 6) {
						this.$message.info('请输入6位数字原密码');
						return;
					}
					if (!this.pay_password) {
						this.$message.info('请输入新密码');
						return;
					}
					if (this.pay_password.length < 6) {
						this.$message.info('请输入6位数字新密码');
						return;
					}
					if (!this.pay_password_code) {
						this.$message.info('请输入确认密码');
						return;
					}
					if (this.pay_password !== this.pay_password_code) {
						this.$message.info('两次输入密码不一致');
						return;
					}
					this.$api.post(global.apiUrls.postEditPayPsd, {
						security_code: this.security_code,
						pay_password: this.pay_password,
						pay_password_code: this.pay_password_code
					}).then(res => {
						this.$message.info(res.data.msg);
						if (res.data.code == 1) {
							setTimeout(() => {
								uni.navigateBack();
							}, 800)
						}
					})
				}
			},
			isBack() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		.bar_info {
			width: 750rpx;
			height: 88rpx;
			overflow: hidden;
			z-index: 10;
			position: fixed;
			top: 0rpx;
		
			.title_bar {
				padding: 0 32rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
		
				.title_bar_left {
					width: 50rpx;
				}
		
				.title_bar_center {
					line-height: 88rpx;
					font-size: 36rpx;
					font-weight: 400;
				}
		
				.title_bar_right {
					width: 50rpx;
				}
			}
		}
		.set_content {
			padding: 30rpx;
			.set_list {
				background: #fff;
				border-radius: 20rpx;
				padding: 0 30rpx;
				margin-bottom: 24rpx;
				.list_item {
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 40rpx 0;
					border-bottom: 1rpx solid #eee;
					.list_item_left {
						font-size: 30rpx;
						width: 140rpx;
					}
					.list_item_right {
						width: calc(100% - 140rpx);
						font-size: 30rpx;
						text-align: right;
					}
				}
				.no_border {
					border-bottom: 1rpx solid transparent;
				}
			}
		}
		.save_btn {
			width: 610rpx;
			height: 100rpx;
			background: #0278FC;
			border-radius: 22rpx;
			font-size: 32rpx;
			color: #fff;
			text-align: center;
			line-height: 100rpx;
			margin: 432rpx auto 0;
		}
	}
</style>